/*
 * @Description: 
 * @Author: baron
 * @Date: 2024-08-08 13:33:08
 * @LastEditTime: 2024-08-08 13:36:08
 * @LastEditors: baron
 */
import {
    getWechatId
} from '@/apis/auth';

// 获取OpenId和UnionId
export const getOpenUnionId = () => {
    return new Promise((resolve, reject) => {
        uni.login({
            provider: 'weixin',
            async success(res) {
                try {
                    const {
                        data,
                        code,
                        msg
                    } = await getWechatId(res.code);
                    if (code === 200 && data.openId && data.unionId) {
                        return resolve(data);
                    }
                    return reject(msg);
                    // if(data)
                } catch (error) {
                    console.log(error);
                    return reject(error);
                }
            },
            fail() {
                uni.hideLoading();
                return reject();
            }
        });
    });
};